package by.koleda.photoupdater.helpers;

import java.io.InputStream;
import java.io.OutputStream;

import android.util.Log;

public class Utils {
	
	public static final String TAG = Utils.class.getSimpleName();
	
	public static void copyStream(InputStream is, OutputStream os) {

		final int buffer_size = 1024;
		try {
			byte[] bytes = new byte[buffer_size];
			while (true) {
				int count = is.read(bytes, 0, buffer_size);
				if (count == -1) {
					break;
				}
				os.write(bytes, 0, count);
			}
		} catch (Exception e) {
			Log.w(TAG, e.getMessage());
		}
	}
	
	public static String formatNumber(String phoneNumber) {
		if (phoneNumber == null) {
			return null;
		}
		if (phoneNumber.equals("")) {
			return phoneNumber;
		}
		phoneNumber.replaceAll("\\D+", "");
		if (phoneNumber.length()<7) {
			return phoneNumber;
		}
		return phoneNumber.substring(phoneNumber.length()-7);
	}

}
